<!DOCTYPE html>
<html>

<head>
	<title>小水滴</title>
	<meta name="keywords"  />
	<meta name="description" content="" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
	<!-- Custom Theme files 1280*559-->
  	<link href="/static/js/layui/css/layui.css" rel="stylesheet">
	<link href="/static/js/layui/css/form.css" rel="stylesheet">
	<!-- //Custom Theme files -->
	<!-- 青、赤、黄、白、黑 -->
  	<script src="/static/js/layui/layui.js"></script>
  	<script src="/static/js/common.js"></script>
</head>

<body class="body-page">
	<div class="search layui-form" lay-filter="search">
		<div class="form-table">
			<div class="form-row">
				<div class="form-cell">
					<label>归属</label>
				</div>
				<div class="form-cell">
					<select name="gs" lay-filter="gs" lay-search="" lay-verify=""></select>
				</div>
				<div class="form-cell">
					<label>归属项目</label>
				</div>
				<div class="form-cell">
					<select name="projectId" lay-filter="projectId" lay-search="" lay-verify=""></select>
				</div>
				<div class="form-cell">
					<label>任务状态</label>
				</div>
				<div class="form-cell">
					<select name="status" lay-filter="status" lay-search="" lay-verify=""></select>
				</div>
			</div>
			<div class="form-row">
				<div class="form-cell">
					<label>项目优先级</label>
				</div>
				<div class="form-cell">
					<select name="priority" lay-filter="priority" lay-search="" lay-verify="">
						<option value="">请选择</option>
						<option value="1">高</option>
						<option value="2">中</option>
						<option value="3">低</option>
					</select>
				</div>
				<div class="form-cell">
					<button class="layui-btn layui-btn-sm" id="search">搜索</button>
					<button class="layui-btn layui-btn-sm" id="fullScreen">全屏</button>
				</div>
			</div>
		</div>
	</div>
	<div class="grid">
		<table class="layui-hide" id="table" lay-filter="table"></table>
	</div>
</body>
<script>
	var tableId = 'table'+c.uuid();
	var editArea = ['1000px', '500px'];

	$(function(){

		c.table({
			elem: '#table',
			url: '/view/project',
			id:tableId,
			height: 'full',
			cellMinWidth: 80,
			page: false,
			parseData: function(res){ // res 即为原始返回的数据
				return {
				"code": 0, // 解析接口状态
				"msg": '', // 解析提示文本
				"count": 10000, // 解析数据长度
				"data": res.data // 解析数据列表
				};
			},
			cols: [[
				{field:'cname',title:'项目简称',width:120},
				{field:'taskName',title:'任务名称',width:260},
				{field:'status',title:'任务状态',width:100,templet:function(row){
					for( var i=0 ; i<statusArr.length ; i++ ){
						if( statusArr[i].id == row.status ){
							return statusArr[i].name;
						}
					}
					return '';
				}},
				{field:'yfs',title:'研发',width:90},
				{field:'cs',title:'测试',width:90},
				{field:'cp',title:'产品',width:90},
				{field:'inManager',title:'经理',width:90},
				{field:'startTime',title:'开始时间',width:108,templet:function(row){
					return row.startTime ? row.startTime.substr(0,10) : '';
				}},
				{field:'stopTime',title:'提测时间',width:108,templet:function(row){
					return row.stopTime ? row.stopTime.substr(0,10) : '';
				}},
				{field:'onlineTime',title:'上线时间',width:108,templet:function(row){
					return row.onlineTime ? row.onlineTime.substr(0,10) : '';
				}},
				{field:'remarks',title:'任务备注',width:180}
			]],
			error: function(res, msg){
				console.log(res, msg)
			}
		});

		$('#fullScreen').click(function(){
			window.open("/html/project_view.html", "_blank");
		});

		$('#create').click(function(){
			c.window({
				area: editArea,
				content:'/html/user_add.html'
			});
		});

		$('#search').click(function(){
			reloadTable({where:form.val('search')});
		});

		c.request('project/page',{page:1,limit:1000},function(resp){
			if( resp.code == 0 ){
				var ele = $('select[name="projectId"]');
				var list = resp.data.list;
				ele.empty();
				ele.append('<option value="">请选择或搜索</option>');
				for( var i=0 ; i<list.length ; i++ ){
					var row = list[i];
					ele.append('<option value="'+row.id+'">'+row.cname+'</option>');
				}
				form.render(ele);
			}else{
				c.message(resp.message);
			}
		});

		c.request('view/project',{page:1,limit:1000},function(resp){
			if( resp.code == 200 ){
				var d = resp.data;
				loadTableData(d);
			}else{
				c.message(resp.message);
			}
		});

		loadGs();
	});

	function loadGs(){
		var ele = $('select[name="gs"]');
		var list = [{id:1,name:'项目组'},{id:2,name:'非项目组'}];
		ele.empty();
		ele.append('<option value="">请选择或搜索</option>');
		for( var i=0 ; i<list.length ; i++ ){
			var row = list[i];
			ele.append('<option value="'+row.id+'">'+row.name+'</option>');
		}
		form.render(ele);
	}

	loadStatus();
	function loadStatus(){
		var ele = $('select[name="status"]');
		ele.empty();
		ele.append('<option value="">请选择或搜索</option>');
		for( var i=0 ; i<statusArr.length ; i++ ){
			var row = statusArr[i];
			ele.append('<option value="'+row.id+'">'+row.name+'</option>');
		}
		form.render(ele);
	}

	function reloadTable(queryParams){
		queryParams = queryParams ? queryParams : {};
		table.reloadData(tableId,queryParams,true);
	}

	function editRow(id){
		c.window({
			area: editArea,
			content:'/html/user_add.html?id='+id
		});
	}

	function deleteRow(id){
    	layer.confirm('确定要删除吗？', {icon: 3, title:'提示'}, function(index){
			c.request('user/delete',{id:id},function(resp){
				if( resp.code == 200 ){
					c.message('删除成功');
				}else{
					c.message(resp.message);
				}
				reloadTable();
			});
			layer.close(index);
		});
	}

	
</script>
</html>